package com.lry.basic.netty.protocol.client;


import com.lry.basic.netty.protocol.struct.NettyMsg;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

public class ClientHandler  extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    	try {
    	 	NettyMsg message = (NettyMsg)msg;
        	System.out.println("Client receive message from server: " + message.getBody());
		} finally {
			ReferenceCountUtil.release(msg);
		}
    }
    
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
    	System.out.println("----------客户端数据读异常-----------");
        ctx.close();
    }
}
